<template>
  <div class="sub-out border_style">
    <div class="search border_style bg_style">
      <Select style="width:200px;margin-right:10px" clearable class="select-border" v-model="page.subscribeval"
        v-if="!showDatePick">
        <Option v-for="(item, index) in page.subscribelist" :value="item.state"
          @click.native="getSelectItem(item.state)" :key="index" :label="item.name">{{ item.name }}</Option>
      </Select>
      <YsDatePicker type="daterange" @on-change="handleChange" v-else :format="`yyyy-MM-dd`" placement="bottom-end"
        placeholder="请选择自定义日期" style="width:200px;margin-right:10px"></YsDatePicker>

      <Select style="width:200px;margin-right:10px" clearable class="select-border" v-model="page.stateVal">
        <Option v-for="(item, index) in page.detect_state_list" :value="item.detect_state"
          @click.native="getAppUsageList()" :key="index" :label="item.name">{{ item.name }}</Option>
      </Select>

      <YsInput class="search-input" clearable v-model.trim="pege_param.job_code" placeholder="请输入任务编号"></YsInput>

      <Select style="width:200px;margin-right:10px" clearable class="select-border" placeholder="请选择材质"
        v-model="pege_param.mat_id">
        <Option v-for="(item, index) in materialInfos" @click.native="getAppUsageList()" :value="item.id" :key="index">
          {{ item.mat_name }}
        </Option>
      </Select>

      <div v-if="showDatePick" class="analysis-add bg_style border_style" @click="backToSelect">
        <YsIcon type="md-swap" class="text_01" />
      </div>

      <YsButton type="primary" class="searchBtn" @click="getAppUsageList">查询</YsButton>
      <div class="open-btn">
        <YsButton class="right-between" @click="handleTask(1)">新增</YsButton>
      </div>
    </div>
    <proTable ref="subscribeTableDom" class="table-st  border_style bg_style" :loading="page.tableLoad"
      :columns="page.columns" :data="page.data" @clickPage="onClickPage" :current="pege_param.start_recd"
      :total="page.allTotal" :pageSize="pege_param.limit_recd">
    </proTable>

    <pro-dialog ref="TestTaskDom" width="608" :nopadding="true" title="创建检测任务">
      <div class="model-box" style="padding: 0px 24px 24px">
        <YsForm :model="jobInfo" label-position="top">
          <YsFormItem class="renwu" label="创建方式">
            <Select class="select-border" size="large" v-model="creation_data">
              <Option v-for="(item, index) in creationMethod" :value="item.id" @click.native="handleCreationItem(item)"
                :key="index">{{ item.name }}</Option>
            </Select>
          </YsFormItem>
          <template v-if="creation_data==1">
            <YsFormItem class="renwu" label="任务名称">
              <YsInput size="large" style="width:560px;float:left;" v-model="jobInfo.detect_name"></YsInput>
            </YsFormItem>
            <YsFormItem label="选择数据">
              <YsInput size="large" class="icon-input" placeholder="请选择"  style="width: 514px; float: left;" :disabled="true"></YsInput>
              <div class="icon-chain" @click="openUpload(1)">
                <span class="icon iconfont">&#xe70e;</span>
              </div>
            </YsFormItem>
          </template>
          <template v-else>
            <YsFormItem class="renwu" label="选择底片">
              <YsInput size="large" class="icon-input" style="width: 514px; float: left;" :disabled="true"></YsInput>
              <div class="icon-chain" @click="handleNegative">
                <span class="icon iconfont icon-xuanzedipian"></span>
              </div>
            </YsFormItem>
            <YsFormItem label="检验任务">
              <div class="ren_w border_style">
                <YsRow :gutter="10">
                  <YsCol span="8" class="ren_item" v-for="(item,index) in taskDistory" :key="index"
                    @click.native="viewTaskDetails(item)">
                    <div class="rw-del" @click="deleteTaskDetails(item,index)">
                      <div class="gang"></div>
                    </div>
                    <div class="rw-item">{{item.jobInfo.detect_code}}</div>
                  </YsCol>
                </YsRow>
              </div>
            </YsFormItem>
          </template>
        </YsForm>
        <YsRow class="foot-btn" style="margin-top: 10px">
          <YsButton @click="handleTask(2)" size="large">关闭</YsButton>
          <YsButton @click="changePerformTasks()" :disabled="fileSuccess" size="large" type="primary">执行任务</YsButton>
        </YsRow>
      </div>
    </pro-dialog>

    <pro-dialog ref="oploadTestDom" width="1060" class="nopad100" :nopadding="true" title="上传检测数据">
      <div class="model-box" style="padding: 0 18px 24px 24px">
        <YsForm class="add-form" label-position="top" ref="updateFrom" :rules="ruleValidate" :model="dataInfo" inline>
          <YsRow :gutter="10">
            <YsCol span="8">
              <YsFormItem label="项目" prop="projectId">
                <Select class="select-border" size="large" v-model="dataInfo.projectId">
                  <Option v-for="(item, index) in projectInfos" :value="item.id" :key="index">{{ item.pd_name }}
                  </Option>
                </Select>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="委托单" prop="entrust">
                <Select class="select-border" size="large" v-model="dataInfo.entrust">
                  <Option v-for="(item, index) in entrustInfos" :value="item.id" :key="index">{{ item.pd_name }}
                  </Option>
                </Select>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="设备类型" prop="part_id">
                <Select class="select-border" size="large" v-model="dataInfo.part_id">
                  <Option v-for="(item, index) in partInfos" :value="item.id" :key="index">{{ item.ep_name }}</Option>
                </Select>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="母材材质" prop="mat_id">
                <Select class="select-border" size="large" v-model="dataInfo.mat_id">
                  <Option v-for="(item, index) in materialInfos" :value="item.id" :key="index">{{ item.mat_name }}
                  </Option>
                </Select>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="母材公称厚度/壁厚" prop="material_thick">
                <YsInput type="text" size="large" v-model.trim="dataInfo.material_thick" placeholder="请输入母材公称厚度/壁厚">
                </YsInput>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="致密性" prop="compactness">
                <Select class="select-border" size="large" v-model="dataInfo.compactness">
                  <Option v-for="(item, index) in condition" :value="item.value" :key="index">{{ item.name }}</Option>
                </Select>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="射线源" prop="radial_source">
                <YsInput type="text" size="large" v-model.trim="dataInfo.radial_source" placeholder="请输入射线源"></YsInput>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="像素距离(um)" prop="pixel">
                <YsInput type="text" size="large" v-model.number="dataInfo.pixel" placeholder="请输入像素距离"></YsInput>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="管道外径(mm)" prop="pipe_outer_diameter">
                <YsInput type="text" size="large" v-model.trim="dataInfo.pipe_outer_diameter" placeholder="请输入管道外径">
                </YsInput>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="焊缝总长度(mm)">
                <YsInput type="text" size="large" v-model.number="dataInfo.craft_sum_length" placeholder="请输入焊缝总长度">
                </YsInput>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="焊接方式" prop="craft_id">
                <Select class="select-border" size="large" v-model="dataInfo.craft_id">
                  <Option v-for="(item, index) in craftInfos" :value="item.id" :key="index">{{ item.cf_name }}</Option>
                </Select>
              </YsFormItem>
            </YsCol>

            <YsCol span="8">
              <YsFormItem label="黑度检测规则">
                <Select class="select-border" filterable clearable :transfer="true" ref="stationSelect"
                  :label-in-value="true" @on-query-change="clearInput" @on-open-change="onOpenChange"
                  @on-clear="onClear" :remote-method="remotedMethod" size="large" v-model="dataInfo.rule_id">
                  <Option v-for="(item, index) in ruleBeansArr" :value="item.id" :label="item.rule_name" :key="index">
                  </Option>
                </Select>
              </YsFormItem>
            </YsCol>
            <YsCol span="8">
              <YsFormItem label="底片截取规则" prop="exp_id">
                <Select class="select-border" size="large" v-model="dataInfo.exp_id">
                  <Option v-for="(item, index) in hdinfos" :value="item.id" :key="index">{{ item.exp_name }}</Option>
                </Select>
              </YsFormItem>
            </YsCol>
          </YsRow>
          <YsRow>
            <YsCol span="24" class="setroute" v-if="creation_data===1">
              <YsFormItem label="上传文件">
                <div class="uploadstyle">
                  <YsUpload :action="fileupload.uploadpath" :format="['jpg', 'jpeg', 'png', 'dcm']" ref="upload"
                    class="uploaduoter ivu-input " :on-format-error="handleFormatError" :default-file-list="defaultList"
                    :on-exceeded-size="handleMaxSize" :before-upload="uploadProcessThen"
                    :on-success="(res, file, fileList) => handleSuccess(res, file, fileList, this.fileupload.upload_path)"
                    :on-remove="(res, file, fileList) => handleRemove(res, file, fileList)" multiple>
                    <YsIcon type="icon iconfont icon-bendishangchuan"></YsIcon>
                  </YsUpload>
                </div>
              </YsFormItem>
            </YsCol>
          </YsRow>
          <YsRow>
            <YsCol span="24">
              <YsFormItem label="备注">
                <YsInput v-model="dataInfo.data_desc" type="textarea" maxlength="500" placeholder="最长可输入500字符"
                  :autosize="{ minRows: 8, maxRows: 5 }"></YsInput>
              </YsFormItem>
            </YsCol>
          </YsRow>
        </YsForm>
        <YsRow class="foot-btn" style="margin-right: 10px;">
          <YsButton size="large" @click="$refs.oploadTestDom.close()">取消</YsButton>
          <YsButton size="large" :disabled="fileSuccess" @click="openClick('updateFrom')" type="primary">上传</YsButton>
        </YsRow>
      </div>
    </pro-dialog>

    <!-- <pro-dialog ref="routeDom" width="628" :nopadding="true" title="路径">
      <div class="model-box" style="padding: 32px">
        <YsForm label-position="top" :model="routePath">
          <YsFormItem class="renwu" label="导入路径：">
            <YsInput size="large" style="width: 498px;" type="file" :format="['text']" id="get-files" v-model="routePath.import_path"></YsInput>
            <YsButton size="small" style="height: 46px;margin-left:10px" type="primary">浏览</YsButton>
          </YsFormItem>
          <YsFormItem label="检测后存储路径：">
            <input type="file" id="fileInput"  accept=".txt,text/plain"  onchange="fileChange(this);">
            <YsButton size="small" style="height:46px;margin-left:10px" type="primary">浏览</YsButton>
          </YsFormItem>
        </YsForm>
        <YsRow class="foot-btn" style="margin-top: 50px">
          <YsButton size="large" @click="uploadConfirm" type="primary">确定</YsButton>
          <YsButton size="large" @click="uploadCancel">取消</YsButton>
        </YsRow>
      </div>
    </pro-dialog> -->

    <pro-dialog class="photos" ref="photosDom" width="960" :nopadding="true" title="待复拍底片清单">
      <div class="model-box" style="padding: 0 24px 24px">
        <YsRow>
          <div class="photos-title  text_01">待复拍底片清单</div>
          <ul class="photos-list ">
            <li><label class="text_01">报告编号：</label><span class="text_01">3428066080</span></li>
            <li><label class="text_01">设备类型：</label><span class="text_01">承压设备熔化焊焊接接头</span></li>
            <li><label class="text_01">材质：</label><span class="text_01">铜</span></li>
            <li><label class="text_01">焊接方式：</label><span class="text_01">加垫板单面焊</span></li>
          </ul>
          <div class="photos-table">
            <YsTable :columns="tableColumn" :border="true" width="100%" :data="tableData">
              <template slot="yx-1" slot-scope="{ row }">
                <div class="photos-Import">
                  <p>请导入图片</p>
                  <span class="icon iconfont icon-a-lujing22614"></span>
                  <span class="icon iconfont icon-bendishangchuan"></span>
                </div>
              </template>
            </YsTable>
          </div>
        </YsRow>
        <YsRow class="foot-btn" style="margin-top: 24px">
          <YsButton size="large">PDF下载</YsButton>
          <YsButton size="large">打印</YsButton>
          <YsButton size="large" @click="photosConfirm" type="primary">提交</YsButton>
        </YsRow>
      </div>
    </pro-dialog>
    <historical-photograph ref="photographDom" :partInfos="partInfos" :materialInfos="materialInfos"
      :projectInfos="projectInfos" @setDistorySlice="setDistorySlice">
    </historical-photograph>
  </div>
</template>


<script>
import TeadTitle from "../../components/Main/headTitle.vue";
import setTime from "../../utils/setTime";
import HistoricalPhotograph from "./components/historicalPhotograph.vue";
import { mapState, mapGetters, mapActions } from "vuex";
import { ys_utils } from 'ys-utils-js';
import { json } from "body-parser";
export default {
  name: "application",
  components: {
    TeadTitle,
    HistoricalPhotograph
  },
  computed: {
    ...mapState(['curTheme']),
    ...mapGetters(["getTabList", "getServiceStepList"]),
  },
  data() {
    return {
      taskDistory: [],
      tasksFlag: true,
      fileSuccess: false,
      craftInfos: [],
      routePath: {
        import_path: '',
        storage_path: ''
      },
      currentFile: [],
      tableColumn: [
        {
          title: '序号',
          type: 'index',
          align: 'center',
          width: 70
        },
        {
          title: '底片名称',
          key: "rs_cn_name",
          align: 'center',
        },
        {
          title: '底片标识号',
          key: "rs_cn_name",
          align: 'center',

        },
        {
          title: '复拍底片',
          key: "rs_cn_name",
          align: 'center',
          slot: 'yx-1'
        },
      ],
      tableData: [
        {
          rs_cn_name: "1111"
        },
        {
          rs_cn_name: "3333"
        }
      ],
      creationMethod: [{ name: "手动创建", id: 1 }, { name: "基于历史底片创建", id: 2 }],
      ruleBeansArr: [],//黑度范围
      condition: [{ name: "高", value: 1 }, { name: "低", value: 2 }],
      ruleValidate: {
        compactness: [
          { required: true, message: '请选择致密性', type: 'number', trigger: 'change' }
        ],
        mat_id: [
          { required: true, message: '请选择母材材质', type: 'number', trigger: 'change' }
        ],
        material_thick: [
          { required: true, message: '请输入母材材质厚度', trigger: 'blur' }
        ],
        gray_level: [
          { required: true, message: '请输入灰度阶位', trigger: 'blur' }
        ],
        from_type: [
          { required: true, message: '请输入来源类型', trigger: 'blur' }
        ],
        pixel: [
          { required: true, message: '请输入像素距离', type: 'number', trigger: 'blur' }
        ],
        radial_source: [
          { required: true, message: '请输入射线源', trigger: 'blur' }
        ],
        part_id: [
          { required: true, message: '请选择设备类型', type: 'number', trigger: 'change' }
        ],
        craft_id: [
          { required: true, message: '请选择焊接方式', type: 'number', trigger: 'change' }
        ],
        projectId: [
          { required: true, message: '请选择项目', type: 'number', trigger: 'change' }
        ],
        // entrust: [
        //   { required: true, message: '请选择委托单', type: 'number', trigger: 'change' }
        // ],
      },
      defaultList: [],
      //材质信息
      dataInfo: {
        projectId: "",//为了验证做校验用
        entrust:"",//委托单
        detect_id: "", //检测任务ID
        data_desc: "", //数据描述
        part_id: "",//设备类型ID
        mat_id: "",//母材材质ID
        material_thick: "",//母材材质厚度
        pipe_outer_diameter: "",//管外径
        exp_id: "",//底片标识
        compactness: "",//致密性：1-高，2-低
        pixel: "",//像素距离
        gray_level: "",//灰度阶位
        from_type: "",//来源类型
        radial_source: "",//射线源
        img_zoom1: "",//图像缩放比：宽
        img_zoom2: "",//图像缩放比：高
        authority: "",//'数据权限：1-私有，2-公开
        // ent_no: "",//租户标识-企业编码
        // ent_name: "",//租户标识-企业名称
        // operator: "",//操作用户ID
        // operator_name: "",//操作用户名称
        // create_time: "",//创建时间
        // update_time: "",//更新时间
        // remark: "",//备注
        rule_id: null,//黑度
        craft_id: null
      },
      ruleBean: {
        rule_name: "",
        rule_type: 1,
        rule_version: "",
        rule_file_name: "",
        remark: "",
        rule_parts: [],
        rule_materials: [],
        current_parts: [], //备用属性
        current_materials: [], //备用属性
      },
      creation_data: 1, //是手动创建还是历史创建
      //app传过来的参数
      jobInfo: {
        app_id: "",
        label: "",
        detect_name: "",
        project_id: "", //项目ID
      },
      //上传地址
      fileInfos: [],
      pege_param: {
        app_id: "",
        job_code: null,
        mat_id: null,
        detect_state: null,
        query_start_time: null,
        query_end_time: null,
        start_recd: 1, //开始数据
        limit_recd: 14, //查询的条数
      },
      fileupload: {
        type: null, //类型
        uploadpath: "", //路径
        upload_name: "", //名字
        upload_path: "",
        data: {},
        name: "",
      },
      page: {
        tableLoad: false,
        stateVal: 0,
        subscribeval: null,
        allTotal: 0,
        subscribelist: [
          { state: 1, name: "最近三天" },
          { state: 2, name: "最近一周" },
          { state: 3, name: "最近一月" },
          { state: 4, name: "自定义查询" },
        ],
        detect_state_list: [
          { detect_state: 0, name: "全部状态" },
          { detect_state: 1, name: "检测中" },
          { detect_state: 2, name: "已完成" },
          { detect_state: 3, name: "未检测" },
        ],
        columns: [
          {
            title: "任务编号",
            minWidth: 100,
            tooltip: true,
            key: "detect_code",
          },
          {
            title: "任务名称",
            minWidth: 100,
            tooltip: true,
            key: "detect_name",
          },
          {
            title: "检测人",
            minWidth: 100,
            tooltip: true,
            key: "to_ent_name",
          },
          {
            title: "开始时间",
            minWidth: 100,
            tooltip: true,
            key: "detect_start_time",
          },
          {
            title: "结束时间",
            minWidth: 100,
            tooltip: true,
            key: "detect_end_time",
            render: (h, params) => {
              if (params.row.detect_end_time == null || params.row.detect_end_time == "") {
                return h("td", { class: 'text-overflow' }, "--");
              } else {
                return h("td", { class: 'text-overflow' }, params.row.detect_end_time);
              }
            },
          },
          {
            title: "用时(分钟)",
            key: "detect_time",
            minWidth: 110,
            tooltip: true,
            render: (h, params) => {
              if (params.row.detect_time == null || params.row.detect_time == "") {
                return h("td", { class: 'text-overflow' }, "--");
              } else {
                return h("td", { class: 'text-overflow' }, params.row.detect_time);
              }
            },
          },
          {
            title: "状态",
            minWidth: 100,
            tooltip: true,
            key: "detect_state_name",
            render: (h, params) => {
              return h("div", {
                class: params.row.detect_state_name == '已完成' ? `${this.curTheme} statestyle01` : params.row.detect_state_name == "检测中" ? 'statestyle02' : "statestyle03",
              }, params.row.detect_state_name);
            }
          },
          {
            title: "样本总量",
            minWidth: 120,
            tooltip: true,
            key: "job_sample_num",
            render: (h, params) => {
              if (params.row.job_sample_num == null || params.row.job_sample_num == "") {
                return h("td", { class: 'text-overflow' }, "--");
              } else {
                return h("td", { class: 'text-overflow' }, params.row.job_sample_num);
              }
            },
          },
          {
            title: "已检测",
            minWidth: 120,
            tooltip: true,
            key: "the_end_sample_num",
          },
          // {
          //   title: "待复拍",
          //   minWidth: 120,
          //   tooltip: true,
          //   key: "job_sample_num2",
          //   render: (h, params) => {
          //     if (params.row.job_sample_num2 == null || params.row.job_sample_num2 == "") {
          //       return h("td", { class: 'text-overflow' }, "0");
          //     } else {
          //       return h("td", {
          //         class: 'text-overflow ',
          //         style: { color: '#0091FF', cursor: 'pointer' },
          //         on: {
          //           click: (event) => {
          //             this.getViewDetails(params.row);
          //             event.stopPropagation();
          //           },
          //         },
          //       }, params.row.job_sample_num);
          //     }
          //   },
          // },
          {
            title: "操作",
            width: 160,
            // align: "center",
            render: (h, params) => {
              return h("div", {
                attrs: { class: "mouse-on" },
              }, [
                h("span", {
                  domProps: {
                    title: "导出",
                  },
                  on: {
                    click: (event) => {
                      this.exportToExcel(params.row);
                      event.stopPropagation();
                    },
                  },
                  class: "textColor",
                  style: {
                    margin: "0 8px 0 0 ",
                  },
                }, '导出'),
                h("span", {
                  domProps: {
                    title: "查看详情",
                  },
                  on: {
                    click: (event) => {
                      this.goImgList(params.row);
                      event.stopPropagation();
                    },
                  },
                  class: "textColor",
                  style: {
                    margin: "0 8px 0 0 ",
                  },
                }, '查看'),
                h("span", {
                  // class: ["iconfont", "icon-a-lujing22614"],
                  domProps: {
                    title: "删除",
                  },
                  on: {
                    click: (event) => {
                      this.handleDlelteItem(params.row);
                      event.stopPropagation();
                    },
                  },
                  class: "textColor2",
                }, '删除'),
              ]);
            },
          },
        ],
        data: [],
      },
      entrustInfos:[],//委托单
      materialInfos: [],//材质集合
      projectInfos: [],//项目列表
      partInfos: [],
      hdinfos: [],//黑度集合
      //自定义日期
      showDatePick: false,
    };
  },
  methods: {
    ...mapActions([
      "getPageDetectJobList",
      "setDetectJobAdd",
      "createSpringJobOfFileLibraryAPI",
      "setTempUploadDir",
      "detectJobDel",
      "getPageEquPart",
      "getPageEquMaterial",
      "getPageAllCraft",
      "jobRateExcel",
      "getRuleTypeStateReleaseAPI",
      "getPageQueryProjectAPI",
      "getAllExpAPI"
    ]),
    fileChange(e) {
    },
    //获取服务列表 getAppUsageList
    getAppUsageList() {
      let _this = this;
      this.page.tableLoad = true;
      _this.pege_param.detect_state = this.page.stateVal ? this.page.stateVal : null;
      _this.getPageDetectJobList(this.pege_param).then((res) => {
        let { data, msg, scode, status } = res;
        _this.page.tableLoad = false;
        if (status === "ok") {
          this.page.data = data.detectJobBeans;
          this.page.allTotal = data.all_recd;
        } else {
          _this.$YsMessage.error(msg);
          this.page.data = [];
          this.page.allTotal = 0;
        }
      }).catch((err) => {
        _this.page.tableLoad = false;
        _this.$YsMessage.error("获取数据失败");
      });
    },
    //分页
    onClickPage(pageNum) {
      this.pege_param.start_recd = pageNum;
      this.getAppUsageList();
    },
    //app订阅是否 通行
    handleAppStateClick(flag, row) {
      let _this = this;
      _this.editSubOrderDetail({
        sub_code: row.sub_code,
        sub_order_no: row.sub_order_no,
        sub_state_code: flag ? "DYZT_1002" : "DYZT_1003",
      })
        .then((res) => {
          let { data, msg, scode, status } = res;
          if (status === "ok") {
            _this.$YsMessage.success(data.message_text);
          } else {
            _this.$YsMessage.error(msg);
          }
        })
        .catch((err) => {
          _this.$YsMessage.error("提交失败");
        });
    },
    //新建任务
    handleTask(flag) {
      if (flag == 1) {
        this.tasksFlag = false
        this.creation_data = 1
        this.jobInfo.detect_name = ""
        this.$refs.TestTaskDom.show();
        if (this.$route.query && this.$route.query.state == 1) {
          this.$refs.TestTaskDom.show();
        } else {
          this.$YsMessage.info("未上架不能新增");
          this.$refs.TestTaskDom.close();
        }
      } else {
        this.$refs.TestTaskDom.close();
      }
    },
    //上传选中
    openUpload(flag, item) {
      if (flag == 1) {
        this.dataInfo = this.$options.data().dataInfo;
        this.defaultList = this.$options.data().defaultList;
        this.$refs.updateFrom.resetFields()
        this.getSheBeiBuWei()
        this.getObjectList()
        this.getCaiZhiWeiHu()
        this.getHanJieGongYi()
        this.$refs.oploadTestDom.show();
      }
    },
    //删除
    handleDlelteItem(item) {
      let _this = this;
      this.$YsModal.confirm({
        title: "删除",
        content: "<p>确认是否删除！</p>",
        onOk: () => {
          _this
            .detectJobDel({ jobInfo: { id: item.id } })
            .then((res) => {
              let { data, msg, scode, status } = res;
              if (status === "ok") {
                _this.$YsMessage.success("删除成功");
                _this.getAppUsageList();
              } else {
                _this.$YsMessage.error(msg);
              }
            })
            .catch((err) => {
              _this.$YsMessage.error("删除失败");
            });
        },
      });
    },
    //返回按钮显示选择框隐藏日期选择
    backToSelect() {
      this.showDatePick = false;
      this.pege_param.query_start_time = ``;
      this.pege_param.query_end_time = ``;
    },
    //获取时间
    getSelectItem(item) {
      let time = [];
      let date = new Date();
      this.page.subscribeval = item;
      switch (item) {
        case 1:
          time = setTime.getDateRange(date, 2, true);
          break;
        case 2:
          time = setTime.getDateRange(date, 6, true);
          break;
        case 3:
          time = setTime.getDateRange(date, 30, true);
          break;
        case 4:
          this.showDatePick = true;
          break;
        default:
          throw [];
      }
      if (time.length == 2) {
        this.pege_param.query_start_time = `${time[0]} 00:00:00`;
        this.pege_param.query_end_time = `${time[1]} 23:59:59`;
      }
      this.getAppUsageList();
    },
    //自定义获取时间
    handleChange(time) {
      let flag = time.some(v => v == "")
      if (flag) return this.page.data = []
      this.pege_param.query_start_time = `${time[0]} 00:00:00`;
      this.pege_param.query_end_time = `${time[1]} 23:59:59`;
      this.getAppUsageList();
    },
    //执行任务
    changePerformTasks() {
      let _this = this;
      if (this.creation_data === 1) {
        if (this.tasksFlag) return this.$YsMessage.warning("请选择检测数据");
        if (!this.jobInfo.detect_name) return this.$YsMessage.warning("请输入任务名称");
        this.tasksFlag = true
        _this.setDetectJobAdd({ jobInfo: _this.jobInfo, dataInfo: _this.dataInfo, fileInfos: _this.fileInfos }).then((res) => {
          let { data, msg, scode, status } = res;
          if (status === "ok") {
            _this.$YsMessage.success("新增任务成功");
            this.$refs.TestTaskDom.close();
            _this.dataInfo = this.$options.data().dataInfo;
            _this.fileupload = this.$options.data().fileupload;
            _this.jobInfo = this.$options.data().jobInfo;
            _this.fileInfos = [];
            _this.$refs.upload.clearFiles();
            this.getAppUsageList();
          } else {
            _this.$YsMessage.error(msg);
          }
        }).catch((err) => {
          this.tasksFlag = false
          _this.$YsMessage.error("新增任务失败");
        });
        //基于底片库创建任务
      } else {
        _this.createSpringJobOfFileLibraryAPI({ createJobBeans: this.taskDistory }).then((res) => {
          let { data, msg, scode, status } = res;
          if (status === "ok") {
            _this.$YsMessage.success(data.message_text);
            _this.$refs.TestTaskDom.close();
            _this.dataInfo = this.$options.data().dataInfo;
            _this.fileupload = this.$options.data().fileupload;
            _this.jobInfo = this.$options.data().jobInfo;
            _this.fileInfos = [];
            _this.getAppUsageList();
          } else {
            _this.$YsMessage.error(msg);
          }
        }).catch((err) => {
          this.tasksFlag = false
          _this.$YsMessage.error("新增任务失败");
        });
      }

    },
    //上传
    openClick(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.jobInfo.project_id = this.dataInfo.projectId
          this.$refs.oploadTestDom.close();
        }
      });
    },
    //上传成功
    handleSuccess(res, file, fileList, text_path) {
      this.currentFile.push(file)
      if (fileList.length === this.currentFile.length) {
        this.fileSuccess = false
        this.$YsMessage.success({
          content: "上传成功",
          duration: 5
        })
        this.currentFile = this.$options.data().currentFile
      }
    },
    //获取上传地址
    async uploadProcessThen(res, file) {
      this.fileSuccess = true
      this.fileupload.type = res.type; //上传类型
      this.fileupload.upload_name = res.name;
      this.fileupload.author = res.name;
      let imgFolder = await this.setUpload()
      this.fileupload.upload_path = imgFolder.upload_path
      this.fileupload.uploadpath = `${window.GlobalConfig.serviceProxy.BaseUrl}fileupload?uploadPath=${imgFolder.upload_path}`
      this.fileInfos.push({ file_url: `webDownLoad/${imgFolder.upload_path}/${res.name}`, file_name: `${res.name}` })
    },
    //格式
    handleFormatError(file) { },
    //大小
    handleMaxSize(file) { },
    //手动打开页面
    async setUpload() {
      let _this = this;
      return new Promise((resolve, reject) => {
        _this.setTempUploadDir().then((res) => {
          let { data, msg, scode, status } = res;
          if (data.upload_absolute_path && data.upload_path) {
            resolve(data);
          } else {
            reject(null);
          }
        });
      });
    },
    //跳转详情
    goImgList(data) {
      this.$router.push({ name: "picturePreview", query: data });
    },

    //获取设备类型select
    getSheBeiBuWei() {
      let _this = this;
      _this.getPageEquPart({ limit_recd: 99999 }).then((res) => {
        let { data, msg, scode, status } = res;
        if (status === "ok") {
          this.partInfos = data.partInfos
        } else {
          _this.$YsMessage.error(msg);
        }
      }).catch((err) => {
        _this.$YsMessage.error("获取数据失败");
      });
    },

    //获取项目列表
    getObjectList() {
      let _this = this
      _this.getPageQueryProjectAPI({ limit_recd: 99999 }).then(res => {
        let { data, msg, scode, status } = res;
        if (status === 'ok') {
          this.projectInfos = data.projectInfos
        } else {
          _this.$YsMessage.error(msg);
        }
      }).catch(err => {
        _this.$YsMessage.error('获取数据失败');
      })
    },
    //获取材质select
    getCaiZhiWeiHu() {
      let _this = this;
      _this.materialInfos = []
      _this.getPageEquMaterial({ limit_recd: 99999 }).then((res) => {
        let { data, msg, scode, status } = res;
        if (status === "ok") {
          this.materialInfos = data.materialInfos;
        } else {
          _this.$YsMessage.error(msg);
        }
      }).catch((err) => {
        _this.$YsMessage.error("获取数据失败");
      });
    },
    //手动上传
    uploadAuto() {
      this.$refs.routeDom.show()
    },
    //取消
    uploadCancel() {
      this.$refs.routeDom.close()
    },
    //确定提交
    uploadConfirm() {
      this.$refs.routeDom.close()
    },
    //焊接方式
    getHanJieGongYi() {
      let _this = this;
      _this.getPageAllCraft({}).then((res) => {
        let { data, msg, scode, status } = res;
        if (status === "ok") {
          this.craftInfos = data.craftInfos;
        } else {
          _this.$YsMessage.error(msg);
        }
      }).catch((err) => {
        _this.$YsMessage.error("获取数据失败");
      });
    },
    //导出
    exportToExcel(row) {
      window.open(`${window.GlobalConfig.serviceProxy.BaseUrl}export/job_rate?job_id=${row.id}`, '_blank')
    },
    //删除功能
    handleRemove(res, file, fileList) {
      if (res) {
        let index = this.fileInfos.findIndex((itm) => { return itm.file_name == res.name })
        if (index !== -1) {
          this.fileInfos.splice(index, 1)
        }

      }
    },
    //打开弹出查看详情
    getViewDetails(item) {
      this.$refs.photosDom.show()
    },
    //取消
    photosCancel() {
      this.$refs.photosDom.close()

    },
    //确认
    photosConfirm() {
      this.$refs.photosDom.close()
    },
    //远程搜索清空数据
    clearInput(e) {
      if (!e) this.ruleBeansArr = []
    },
    //清空数据
    onClear() {
      setTimeout(() => {
        this.remotedMethod()
      }, 200)
    },
    //没有被选中从新调用接口
    onOpenChange(flag) {
      if (!flag) {
        if (this.ruleBeansArr.length == 0) {
          setTimeout(() => {
            this.remotedMethod()
          }, 200)
        }
      }
    },
    //远程请求
    remotedMethod(query = '') { //当父组件传值进入时调用该方法
      this.getRuleTypeStateReleaseAPI({ rule_type: 6, keyword: query, rule_state: 1 }).then((res) => {
        let { data, msg, scode, status } = res;
        if (status === "ok") {
          this.ruleBeansArr = data.ruleInfos;
        } else {
          this.ruleBeansArr = []
          this.$YsMessage.error(msg);
        }
      }).catch((err) => {
        this.$YsMessage.error("获取数据失败");
      })
    },
    //底片截取规则
    getNegativeList() {
      this.hdinfos = []
      this.getAllExpAPI({}).then(res => {
        let { data, msg, scode, status } = res;
        if (status === "ok") {
          this.hdinfos = data.infos
        } else {
          this.$YsMessage.error(msg);
        }
      }).catch((err) => {
        this.$YsMessage.error("获取数据失败");
      });
    },
    //底片设置
    setDistorySlice(data) {
      this.taskDistory = data
    },
    //选择底片
    handleNegative() {
      this.$refs.photographDom.currentTabChanged()
    },
    //查看详情
    viewTaskDetails(data) {
      this.jobInfo = data.jobInfo
      this.dataInfo = data.dataInfo
      this.fileInfos = data.fileInfos
      this.dataInfo.projectId = data.jobInfo.project_id
      //加载图片列表
      this.defaultList = data.fileInfos.map(v => { return { name: v.file_name, url: v.file_url } })
      this.currentFile = JSON.parse(JSON.stringify(this.defaultList))
      this.$refs.oploadTestDom.show();
    },
    //删除
    deleteTaskDetails(item, index) {
      this.taskDistory.splice(index, 1)
    },
    //切换创建方式
    handleCreationItem(item) {
      if (item.id === 2) {
        this.taskDistory = []
      } else {
        this.jobInfo.detect_name = ""
      }
    }
  },
  created() {
    this.getCaiZhiWeiHu()
    this.getSheBeiBuWei()
    this.getObjectList()
    this.remotedMethod()
    this.getNegativeList()
  },
  mounted() {
    if (this.$route.query && this.$route.query.id) {
      this.jobInfo.app_id = Number(this.$route.query.id);
      this.pege_param.app_id = Number(this.$route.query.id);
      // this.$set(this.$route.meta.crumbs, 2, this.$route.query.app_name);
    } else {
      this.$YsMessage.error("未获取到app_id");
    }
    //请求30天的数据
    this.getSelectItem(3);
  },
  //进入钩子
  beforeRouteEnter(to, frome, next) {
    let appName = ys_utils.getSessionStorage('CurItemInfo') && JSON.parse(ys_utils.getSessionStorage('CurItemInfo'))
    // if (appName) {
    //   to.meta.crumbs[2] = appName.app_name
    // }
    next()
  },
  beforeRouteLeave: (to, from, next) => {

    ys_utils.clearSessionStorage('CurItemInfo')
    next();
  }
};
</script>
<style lang="less" scoped>
::v-deep .ivu-input-wrapper {
  // float: left;
}

.model-box {
  /deep/ .icon-input {
    .ivu-input {
      border-radius: 4px 0 0 4px;
    }
  }

  .icon-chain {
    position: relative;
    margin-left: -2px;
    // z-index: 999;
    width: 48px;
    height: 48px;
    line-height: 48px;
    text-align: center;
    float: left;
    cursor: pointer;
    background: #F5F7FA;
    border: 1px solid #d9dfea;
    border-left: none;
    opacity: 1;
    border-radius: 4px;

    &:hover {
      opacity: .8;
    }

    .icon {
      font-size: 40px;
      color: #405680;
    }
    .icon-xuanzedipian {
      font-size: 20px !important;
      color: #405680;

      opacity: 0.6;
    }

    .xt1 {
      font-size: 20px;
    }
  }

  .formconter {
    padding: 0 16px;

    /deep/.ivu-form-item {
      width: 100%;
    }
  }
}

.photos {
  /deep/ .ivu-modal-header {
    padding-left: 24px !important;
    padding-right: 24px !important;
  }

  /deep/ .ivu-modal-close {
    right: 18px;
  }

  .photos-title {
    height: 76px;
    width: 100%;
    border: 1px solid #e1e6f0;
    line-height: 76px;
    text-align: center;
    font-size: 20px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #405580;
  }

  .photos-list {
    border-left: 1px solid #e1e6f0;
    border-right: 1px solid #e1e6f0;
    display: flex;
    height: 46px;
    line-height: 46px;

    li {
      margin-left: 22px;
      font-size: 16px;
    }
  }

  .photos-table {
    .photos-Import {
      display: flex;

      .icon {
        margin-left: auto;
        cursor: pointer;

        &:hover {
          color: rgb(0, 145, 255);
        }
      }

      .icon-a-lujing22614 {
        &:hover {
          color: #ed4014;
        }
      }
    }

    /deep/ .ivu-table-wrapper {
      box-shadow: none;
      border-radius: 0 0 4px 4px;

      th {
        border-right-color: #e1e6f0 !important;
      }

      td {
        border-right-color: #e1e6f0 !important;
      }
    }
  }
}

/deep/.renwu {
  label {
    width: 100%;
    text-align: left !important;

    &:before {
      content: "*";
      display: inline-block;
      margin-right: 4px;
      line-height: 1;
      font-family: SimSun;
      font-size: 14px;
      color: #d53939;
    }
  }
}

// 弹出
.add-form {

  // padding: 20px;
  // background: #fff;
  // border: 1px solid #cfd7e5;
  .modalSelect {
    /deep/ .ivu-select-input {
      height: 38px !important;
      line-height: 38px !important;
    }
  }

  /deep/ .scaling {
    label {
      width: 100%;
      text-align: left;

      &:before {
        content: "*";
        display: inline-block;
        margin-right: 4px;
        line-height: 1;
        font-family: SimSun;
        font-size: 14px;
        color: #d53939;
      }
    }
  }

  /deep/ .ivu-form-item {
    display: block;
    margin-bottom: 24px;

    .ivu-form-item-error-tip {
      padding-top: 1px;
    }
  }

  /deep/ .input-span {
    color: #405680;
    padding: 2px 10px 0;
  }

  .input-all {
    /deep/ .ivu-form-item-label {
      display: block;
      width: 100%;
      text-align: left;
    }

    /deep/ .ivu-form-item-content {
      display: flex;
      width: 100%;
    }
  }

  .select-btn {
    width: 124px;
    height: 40px;
    background: #ffffff;
    border: 1px solid #0061ff;
    opacity: 1;
    border-radius: 4px;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #0091ff;
  }

  .texts {
    font-size: 16px;
    font-family: PingFangSC-Regular;
    color: #405680;
    margin-right: 10px;
    line-height: 40px;
  }

  .search-btn2 {
    width: 88px;

    height: 40px;
    background: #0061ff;
    color: #ffffff;
    font-size: 16px;
    opacity: 1;
    border-radius: 4px;
    margin-left: 10px;
  }
}

/deep/.statestyle01 {
  width: 60px;
  height: 32px;
  line-height: 32px;
  background: #ebeef5;
  opacity: 1;
  text-align: center;
  border-radius: 4px;
  color: #405680;
  // font-size: 16px;
}

/deep/.theme-blue.statestyle01 {
  background: #364766;
  color: #a3b1cc;
}

/deep/.statestyle02 {
  width: 60px;
  height: 32px;
  line-height: 32px;
  background: rgba(0, 145, 255, 1);
  text-align: center;
  opacity: 1;
  // font-size: 16px;
  color: #fff;
  border-radius: 4px;
}

/deep/.statestyle03 {
  color: #fff;
  text-align: center;
  // font-size: 16px;
  width: 60px;
  height: 32px;
  line-height: 32px;

  background: #13b38f;
  opacity: 1;
  border-radius: 4px;
}

.search {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 72px;
  border: 1px solid #cfd7e5;
  border-radius: 4px;
  margin-bottom: 8px;

  .search-input {
    height: 40px;
    width: 260px;
    margin-right: 10px;
    border-radius: 4px;
  }

  .search-btn {
    margin-left: auto;
  }

  .open-btn {
    margin-left: auto;

    .right-between {
      margin-left: 10px;
    }
  }
}

.foot-btn {
  button {
    min-width: 98px;
  }
}

.than {
  font-size: 16px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #405580;
  margin-top: 8px;
  display: block;
}

.uploadstyle {
  /deep/ .ivu-progress {
    display: none !important;
  }

  /deep/ .uploaduoter {
    display: flex;
    // border: 1px solid #cfd7e5;
    height: 48px;
    border-radius: 4px;
    position: relative;

    .ivu-upload-select {
      margin-left: auto;
      position: absolute;
      right: 14px;
      top: 6px;
      font-size: 22px;
    }

    .ivu-upload-list {
      display: flex;
      width: 90%;
      overflow: hidden;
      margin-top: 0;
      align-items: center;

      .ivu-upload-list-file {
        white-space: nowrap;
        flex-shrink: 0;
        text-overflow: ellipsis;
        overflow: hidden;
        height: 40px;
        max-width: 150px;

        span {
          display: inline-block;
          min-width: 70px;
          max-width: 80%;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          padding-top: 6px;
        }

        .ivu-icon-ios-close {
          padding-top: 4px;
          position: relative;
          top: 4px;
        }
      }
    }
  }
}

/deep/ .mouse-on {
  .icon-a-zu48855:hover {
    cursor: pointer;
    color: #0091ff;
  }
}

/deep/ .mouse-on {
  .icon-a-lujing22614:hover {
    cursor: pointer;
    color: #d53939;
  }
}

/deep/ .textColor {
  color: #0091ff;
  cursor: pointer;

  &:hover {
    // color: #0091ff;
    opacity: 0.8;
  }
}

/deep/ .textColor2 {
  color: #0091ff;

  cursor: pointer;

  &:hover {
    opacity: 0.8;
  }
}

.setroute {
  position: relative;

  .setIp {
    position: absolute;
    left: 95px;
    top: -3px;

    label {
      color: rgb(0, 145, 255);
      font-weight: bold;
    }
  }

  .setBtn {
    position: absolute;
    right: 11px;
    top: -12px;
  }
}

/deep/.nopad100 {
  .ivu-modal {
    top: 100px !important;
  }
}

.sub-out {
  min-width: 815px;
}

/deep/.text-overflow {
  border-bottom: none !important;
}

.right-between {
  width: 80px;
  min-width: 80px;
  height: 40px;
  background: rgba(255, 255, 255, 0.39);
  border: 1px solid #0061ff;
  opacity: 1;
  border-radius: 4px;
  color: #0091ff;
  font-size: 16px;
  font-family: PingFang SC;
}

/deep/.table-footer {
  padding-left: 20px !important;
  padding-right: 20px !important;
}

.searchBtn {
  width: 80px;
  min-width: 80px;
  height: 40px;
  font-family: PingFang SC;
}

.analysis-add {
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid #ccc;
  margin-right: 10px;

  &:hover {
    opacity: 0.8;
  }

  i {
    font-size: 18px;
  }
}

/deep/ .ivu-modal-header {
  padding-left: 24px !important;
  padding-right: 24px !important;
}

/deep/ .ivu-modal-close {
  right: 18px;
}

.table-st {
  border: 1px solid #cfd7e5;
  border-radius: 4px;
}

.task-box {
  width: 378px;
  float: left;
  height: 48px;
  padding: 0 6px;
  border: 1px solid #cfd7e5;
  border-radius: 4px;
  display: flex;
  align-items: center;

  span {
    width: 80px;
    margin-right: 6px;
    font-size: 16px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
}

.ren_w {
  border: 1px solid #fff;
  min-height: 124px;
  border-radius: 4px 4px 4px 4px;
  padding: 24px 16px 0 16px;

  .ren_item {
    cursor: pointer;
    &:hover {
      color: #0091FF;
      cursor: pointer;
    }
  }

  .rw-item {
    width: 100%;
    height: 26px;
    line-height: 26px;
    background: #F5F7FA;
    text-align: center;
    font-size: 16px;
    border-radius: 4px 4px 4px 4px;
    margin-bottom: 24px;
    position: relative;
  }

  .rw-del {
    width: 16px;
    height: 16px;
    background: #FB0000;
    opacity: 1;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    position: absolute;
    right: 0;
    top: -6px;
    display: flex;
    justify-content: center;
    align-items: center;


    .gang {
      width: 6px;
      height: 2px;
      margin-left: 0px;
      background: #FFFFFF;
      opacity: 1;
    }
  }
}
</style>
